﻿using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BleSolution
{
    public class LogHelper
    {
        public static Logger _logger = LogManager.GetCurrentClassLogger();
        public LogHelper()
        {

        }

        /// <summary>
        /// 全都加上异常处理  有时候会出现异常
        /// </summary>
        /// <param name="message"></param>
        /// <param name="category"></param>
        /// <param name="priority"></param>
        public static void WriteLog(string message, int level = 0)
        {
            switch (level)
            {
                case 0:
                    try
                    {
                        _logger.Debug(message);
                    }
                    catch
                    {
                    }
                    break;
                case 1:
                    try
                    {
                        _logger.Warn(message);
                    }
                    catch
                    {
                    }
                    break;
                case 2:
                    try
                    {
                        _logger.Error(message);
                    }
                    catch
                    {
                    }
                    break;
                case 3:
                    try
                    {
                        _logger.Info(message);
                    }
                    catch
                    {
                    }
                    break;
            }
        }

        public static void WriteLog(Exception ex, string str = "", int level = 0)
        {
            switch (level)
            {
                case 0:
                    try
                    {
                        _logger.Debug(str + "->" + ex.Message + ":" + ex.StackTrace);
                    }
                    catch
                    {
                    }
                    break;
                case 1:
                    try
                    {
                        _logger.Warn(str + "->" + ex.Message + ":" + ex.StackTrace);
                    }
                    catch
                    {
                    }
                    break;
                case 2:
                    try
                    {
                        _logger.Error(str + "->" + ex.Message + ":" + ex.StackTrace);

                    }
                    catch
                    {
                    }
                    break;
                case 3:
                    try
                    {
                        _logger.Info(str + "->" + ex.Message + ":" + ex.StackTrace);
                    }
                    catch
                    {
                    }
                    break;
            }
        }

    }
}
